package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.VisitDto;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description CustomerReservationController
 * @Author apeng
 * @Date 2024-10-21
 */
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "参观预约")
public class CustomerReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult cancelledCount(){

          Integer count = reservationService.getCountById();
        return success(count);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult insert(@RequestBody VisitDto visitDto) {
        reservationService.insert(visitDto);
        return success();
    }

    //查询每个事件段剩余预约次数
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余的次数")
    public ResponseResult getCountByTime(Long time){
        List<TimeCountVo> list = reservationService.getCountByTime(time);
        return success(list);
    }

    //分页查询预约
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult page(@ApiParam("页码")
                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @ApiParam("每页数量")
                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                               @ApiParam("状态") Integer status) {
        PageResponse pageResponse  = reservationService.page(pageNum,pageSize,status);
        return success(pageResponse);
    }

    //取消预约
    @PutMapping("/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return success();
    }
}
